﻿@model EquipmentStockInListModel
@using Nop.Core.Domain.XJ
@using Nop.Services.Security

@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    var permissionService = EngineContext.Current.Resolve<IPermissionService>();
    var canManageInsEdit = permissionService.Authorize(StandardPermissionProvider.ManageInsEdit);
    var canManageInsView = permissionService.Authorize(StandardPermissionProvider.ManageInsView);
    var canManageInsAudit = permissionService.Authorize(StandardPermissionProvider.ManageInsAudit);
    var canManageInsConfirm = permissionService.Authorize(StandardPermissionProvider.ManageInsConfirm);

    //page title
    ViewBag.Title = "入库记录";
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("StockIn List");
}

<style>
    .k-grid-footer-locked{
        float:left;
    }
</style>
@Html.AntiForgeryToken()
<div class="content-header clearfix">
    <h1 class="pull-left">
        入库记录
    </h1>
    <div class="pull-right">
        @if (canManageInsEdit)
        {
            <a href="@Url.Action("Create")" class="btn bg-blue">
                <i class="fa fa-plus-square"></i>
                @T("Admin.Common.AddNew")
            </a> 
        }
        </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default panel-search">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <div class="col-md-2 col-search">
                                    <div class="label-wrapper"><label class="control-label" for="SearchSNo" title="">入库单号</label></div>
                                    <div class="col-content">
                                        @Html.NopEditorFor(model => model.SearchSNo)
                                    </div>
                                </div>
                                <div class="col-md-2 col-search">
                                    <div class="label-wrapper"><label class="control-label" for="SearchName" title="">名称</label></div>
                                    <div class="col-content">
                                        @Html.NopEditorFor(model => model.SearchName)
                                    </div>
                                </div>
                                <div class="col-md-2 col-search">
                                    <div class="label-wrapper"><label class="control-label" for="SearchState" title="">状态</label></div>
                                    <div class="col-content">
                                        @Html.NopDropDownListFor(model => model.SearchState, Model.AvailableStates)
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <button type="button" id="search-categories" class="btn btn-primary"><i class="fa fa-search"></i>@T("Admin.Common.Search")</button>
                                    <button type="button" id="cancel-categories" class="btn btn-default"><i class="fa fa-refresh"></i>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="categories-grid"></div>

                    <script>
                        $(document).ready(function () {
                            var columns = [{
                                field: "SNo",
                                title: "入库单号",
                                width: 150,
                                locked: true,
                                headerAttributes: { style: "text-align:center" },
                                template: '#if(@(canManageInsView?1:0)== 1){# <a href="View/#=EquipmentStockInId#">#=SNo#</a> #}else{# #=SNo# #}#'
                            }, {
                                field: "Name",
                                title: "名称",
                                headerAttributes: { style: "text-align:center" },
                                width: 300,
                            }, {
                                field: "Manufacturer",
                                title: "品牌",
                                width: 200,
                                headerAttributes: { style: "text-align:center" },
                            }, {
                                field: "Specification",
                                title: "规格型号",
                                width: 300,
                                headerAttributes: { style: "text-align:center" },
                            }, {
                                field: "Unit",
                                title: "单位",
                                width: 60,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                field: "Price",
                                title: "单价",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:right" },
                                format: "{0:N2}",
                            }, {
                                field: "Amount",
                                title: "数量",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:right" },
                            }, {
                                field: "Total",
                                title: "金额",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:right" },
                                format: "{0:N2}",
                                footerTemplate: '<div style="text-align:right;"><span id=\"e-total-total\"></span></div>',
                            }, {
                                field: "CustomerName",
                                title: "申请人",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                field: "CreatedOn",
                                title: "申请时间",
                                width: 100,
                                type: "date",
                                format: "{0:yyyy/MM/dd}",
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                field: "Reviewer",
                                title: "审核人",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                field: "Keeper",
                                title: "入库人",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                field: "StateName",
                                title: "状态",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            },{
                                field: "EquipmentStockInId",
                                title: "操作",
                                width: 120,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                                template: '# if(State==@((int)StockInStateEnum.保存)&&@(canManageInsEdit?1:0)==1) {# <i class="fa fa-pencil fa-active" title="编辑" onclick="javascript:window.location.href=\'Edit/#=EquipmentStockInId#\';"></i> #} else if(@(canManageInsEdit?1:0)==1) {# <i class="fa fa-pencil fa-disabled" title="编辑" ></i> #} # # if(State==@((int)StockInStateEnum.待审核)&&@(canManageInsAudit?1:0)==1) {# <i class="fa fa-hand-o-up fa-active" title="审核" onclick="javascript:window.location.href=\'Audit/#=EquipmentStockInId#\';"></i> #} else if(@(canManageInsAudit?1:0)==1) {# <i class="fa fa-hand-o-up fa-disabled" title="审核" disabled></i> #} # # if(State==@((int)StockInStateEnum.待入库)&&@(canManageInsConfirm ? 1:0)==1) {# <i class="fa fa-sign-in fa-active" title="入库" onclick="javascript:window.location.href=\'In/#=EquipmentStockInId#\';"></i> #} else if(@(canManageInsConfirm ? 1:0)==1) {# <i class="fa fa-sign-in fa-disabled" title="入库" disabled></i> #} ## if(@(canManageInsView?1:0)==1) {# <i class="fa fa-eye fa-active" title="查看" onclick="javascript:window.location.href=\'View/#=EquipmentStockInId#\';"></i> #} #'
                            }];

                            $("#categories-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("DetailList", "EquipmentStockIn"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: additionalData
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    requestEnd: function (e) {
                                        if (e.type == "read") {
                                            var response = e.response;
                                            if (response) {
                                                //store extra data
                                                reportE = e.response["ExtraData"];
                                            }
                                        }
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(gridPageSizes)],
                                    @Html.Partial("_GridPagerMessages")
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: true, // 滚动
                                resizable: true,  // 缩放
                                columnMenu: true, // 显示列菜单，用户可以从中选择显示或隐藏列
                                dataBound: onDataBoundE,
                                columns: columns
                            });
                        });

                        function onDataBoundE(e) {
                            //update order totals summary
                            if (reportE != "") {
                                $('#e-total-total').text(reportE['Total']);
                            }
                        }
                    </script>

                    <script type="text/javascript">
                        $(document).ready(function() {
                            //search button
                            $('#search-categories').click(function() {
                                //search
                                var grid = $('#categories-grid').data('kendoGrid');
                                grid.dataSource.page(1); //new search. Set page size to 1
                                //grid.dataSource.read(); we already loaded the grid above using "page" function
                                return false;
                            });
                            //cancel button
                            $('#cancel-categories').click(function () {
                                //cancel
                                var grid = $('#categories-grid').data('kendoGrid');
                                $('#@Html.FieldIdFor(model => model.SearchSNo)').val('');
                                $('#@Html.FieldIdFor(model => model.SearchName)').val('');
                                $('#@Html.FieldIdFor(model => model.SearchState)').val('0');
                                grid.dataSource.page(1); //new search. Set page size to 1
                                //grid.dataSource.read(); we already loaded the grid above using "page" function
                                return false;
                            });

                            $("#@Html.FieldIdFor(model => model.SearchSNo)").keydown(function(event) {
                                if (event.keyCode == 13) {
                                    $("#search-categories").click();
                                    return false;
                                }
                            });

                            $("#@Html.FieldIdFor(model => model.SearchName)").keydown(function(event) {
                                if (event.keyCode == 13) {
                                    $("#search-categories").click();
                                    return false;
                                }
                            });

                        });

                        function additionalData() {
                            var data = {
                                SearchSNo: $('#@Html.FieldIdFor(model => model.SearchSNo)').val(),
                                SearchName: $('#@Html.FieldIdFor(model => model.SearchName)').val(),
                                SearchState: $('#@Html.FieldIdFor(model => model.SearchState)').val()
                            };
                            addAntiForgeryToken(data);
                            return data;
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>